﻿
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Shove.Web.UI;

public partial class UserControls_MyOrder_New : UCBase
{
    public UserControls_MyOrder_New()
    {
        Name = "我的订单_2";
        swpas = new ShoveWebPartAttribute[17];

        swpas[0] = new ShoveWebPartAttribute_Int("控件宽度", "1,1004", 770, "控件宽度");
        swpas[1] = new ShoveWebPartAttribute_Color("控件边框颜色", "#C5E4FF", "控件边框颜色");

        swpas[2] = new ShoveWebPartAttribute_Int("导航高度", "1,100", 35, "导航高度");
        swpas[3] = new ShoveWebPartAttribute_Text("导航CSS样式", "", "STYLE3", "导航CSS样式");
        swpas[4] = new ShoveWebPartAttribute_Image("导航背景大图片", "", "images/UserControls/bgbg.jpg", "导航背景大图片");
        swpas[5] = new ShoveWebPartAttribute_Image("导航背景小图片", "", "images/UserControls/dddd.jpg", "导航背景小图片");
        swpas[6] = new ShoveWebPartAttribute_Int("小图片高度", "1,100", 27, "小图片高度");
        swpas[7] = new ShoveWebPartAttribute_Int("小图片宽度", "1,100", 9, "小图片宽度");
        swpas[8] = new ShoveWebPartAttribute_Int("导航前半段所占宽度百分比", "1,100", 3, "导航前半段所占宽度百分比");
        swpas[9] = new ShoveWebPartAttribute_Int("导航后半段所占宽度百分比", "1,100", 97, "导航后半段所占宽度百分比");

        swpas[10] = new ShoveWebPartAttribute_Color("导航下边框颜色", "#C5E4FF", "导航下边框颜色");
        swpas[11] = new ShoveWebPartAttribute_Int("导航下边框高度", "1,100", 1, "小图片宽度");

        swpas[12] = new ShoveWebPartAttribute_Int("表格数据行高", "1,200", 23, "表格数据行高");
        swpas[13] = new ShoveWebPartAttribute_Text("文本CSS样式", "", "blank12", "文本CSS样式");
        swpas[14] = new ShoveWebPartAttribute_Text("表头样式", "", "gStyle", "表头样式");
        swpas[15] = new ShoveWebPartAttribute_Int("表头行高", "1,200", 23, "表头行高");
        swpas[16] = new ShoveWebPartAttribute_Int("每页显示的行数", "1,40", 10, "每页显示的行数");

    }
    private void InitlayOut()
    {
        tabctr.Width = swpAttributes[0];
        tabctr.BgColor = swpAttributes[1];

        tdNavigationimg1.Height = swpAttributes[2];
        tdNavigationimg2.Attributes.Add("class", swpAttributes[3]);
        tdNavigationimg1.Style.Add("background-image", "url('" + swpAttributes[4] + "')");
        tdNavigationimg2.Style.Add("background-image", "url('" + swpAttributes[4] + "')");
        tdNavigationMix.Src = "~/" + swpAttributes[5]; ;
        tdNavigationMix.Height = Shove._Convert.StrToInt(swpAttributes[6], 27);
        tdNavigationMix.Width = Shove._Convert.StrToInt(swpAttributes[7], 9);
        tdNavigationimg1.Width = swpAttributes[8] + "%";
        tdNavigationimg2.Width = swpAttributes[9] + "%";
        tdNavigationLast1.BgColor = swpAttributes[10];
        tdNavigationLast2.BgColor = swpAttributes[10];
        tdNavigationLast1.Height = swpAttributes[11];
        g.CssClass = swpAttributes[13];
        g.HeaderStyle.Height = new Unit(swpAttributes[15]);

        g.HeaderStyle.CssClass = swpAttributes[14];
        gPager.PageSize = Shove._Convert.StrToInt(swpAttributes[16], 10);
    }


    protected void Page_Load(object sender, EventArgs e)
    {
        InitlayOut();

        if (!IsPostBack)
        {
        }
        if (_Customer == null)
        {
            Response.Redirect("Default.aspx?PN=Login");
        }
        else
        {
            BindData();
        }
    }

    private void BindData()
    {
        DataTable dt = null;

        dt = new DAL.Views.V_Shop_SalesMaster().Open("", "CustomerID=" + _Customer.ID + " and ShopID=" + _Customer.ShopID, "");
        if (dt == null)
        {
            return;
        }

        g.DataSource = dt;
        g.DataBind();
        gPager.Visible = (dt.Rows.Count > 0);
    }


    protected void gPager_PageWillChange(object Sender, Shove.Web.UI.PageChangeEventArgs e)
    {
        BindData();
    }

    protected void gPager_SortBefore(object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
    {
        BindData();
    }

    protected void g_ItemCommand(object source, DataGridCommandEventArgs e)
    {
        long ID = Shove._Convert.StrToLong(e.Item.Cells[0].Text, -1);

        //取消
        if (e.CommandName == "Delete")
        {
            DAL.Tables.tbl_Shop_SalesMaster SalesMaster = new DAL.Tables.tbl_Shop_SalesMaster();
            SalesMaster.Status.Value = 3;  //0 未付款 1 已付款 2 已出库  3 已取消

            SalesMaster.Update("ID=" + ID.ToString());
            Response.Redirect("Default.aspx?PN=Good_Center");
        }

        //交易
        if (e.CommandName == "Update")
        {
            DAL.Tables.tbl_Shop_SalesMaster SalesMaster = new DAL.Tables.tbl_Shop_SalesMaster();
            SalesMaster.Status.Value = 4;  //0 未付款 1 已付款 2 已出库  3 已取消

            SalesMaster.Update("ID=" + ID.ToString());
            Response.Redirect("Default.aspx?PN=Good_Center");
        }

        DataBind();
    }

    protected void g_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
    {
        //设置表格样式
        e.Item.Attributes.Add("class", "black12");
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.EditItem)
        {

            e.Item.BackColor = System.Drawing.Color.FromName("#FFFFFF");
            DataRowView drv = (DataRowView)e.Item.DataItem;
            DataRow dr = drv.Row;
            Button btnActivation = (Button)e.Item.Cells[6].FindControl("btnActivation");
            Button btnDel = (Button)e.Item.Cells[6].FindControl("btnDel");
            Button btnEditUserNet = (Button)e.Item.Cells[6].FindControl("btnEditUserNet");
            int AddID = Shove._Convert.StrToInt(dr["ID"].ToString(), 0);
            int Status = Shove._Convert.StrToInt(dr["Status"].ToString(), 0);
            if (Status == 0)//0 未付款 1 已付款 2 已出库  3 已取消
            {
                btnActivation.Enabled = true;
                btnDel.Enabled = true;
                btnEditUserNet.Enabled = false;
            }
            else if (Status == 2)
            {
                btnActivation.Enabled = false;
                btnDel.Enabled = false;
                btnEditUserNet.Enabled = true;
            }
            else
            {
                btnActivation.Enabled = false;
                btnDel.Enabled = false;
                btnEditUserNet.Enabled = false;
            }

            //LoadData(AddID);
            LinkButton lbSel = (LinkButton)e.Item.FindControl("lbSel");
            lbSel.Attributes.Add("onclick", "return intoComparison('" + AddID + "')");

            //支付宝
            double Money = 0;
            Money = Shove._Convert.StrToDouble(e.Item.Cells[4].Text, 0);
            btnActivation.Attributes.Add("onclick", "return OnLinePay('" + AddID.ToString() + "','" + Money.ToString() + "')");

        }
    }
}
